﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter3.Section1
{
    public class Example02
    {
        public Example02()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double[], double> f
                = new V.Function.ToLastType<double[], double>(func);
            double[] at = { 1.0, 0.5 };

            V.IteratedPartialDerivative ddf
                = new V.IteratedPartialDerivative(f, at);

            ddf.WithRespectToFirst = 1;
            ddf.WithRespectToSecond = 1;
            ddf.Compute();
            result += ddf.Result.ToString() + "\r\n";
            
            result += (2.0*Math.Sin(at[0])*Math.Cos(2.0*at[1])).ToString() + "\r\n";
            
            ddf.WithRespectToFirst = 0;
            ddf.WithRespectToSecond = 1;
            ddf.Compute();
            result += ddf.Result.ToString() + "\r\n";

            result += (Math.Cos(at[0]) * Math.Sin(2.0 * at[1])).ToString() + "\r\n";
        }
        private double func(double[] x)
        {
            return Math.Sin(x[0]) * Math.Sin(x[1]) * Math.Sin(x[1]);
        }
    }
}
/* 
0.909297426844838
0.909297426825682
0.454648713659988
0.454648713412841
*/

